package com.lagou.seckill.dto;

import lombok.Data;

import java.io.Serializable;

@Data
public final class Response<T> implements Serializable {

    private Integer status;

    private String code;

    private Boolean success;

    private String message;

    private T data;

    public static Response OK() {
        return OK(null);
    }

    public static <T> Response<T> OK(T data) {
        Response response = new Response();
        response.setCode("0000");
        response.setStatus(200);
        response.setSuccess(true);
        response.setData(data);
        response.setMessage("success!");
        return response;
    }

    public static <T> Response<T> FAIL(String message) {
        return FAIL(500, "9999", message);
    }

    public static <T> Response<T> FAIL(Integer status, String code, String message) {
        Response response = new Response();
        response.setStatus(status);
        response.setCode(code);
        response.setSuccess(false);
        response.setMessage(message);
        return response;
    }
}
